<template>
    <div class="settings">
      <div class="settings-header">
        <h2>系统设置</h2>
        <p class="description">配置系统参数和个性化选项</p>
      </div>
  
      <div class="settings-content">
        <!-- 基本设置 -->
        <div class="settings-section">
          <h3>基本设置</h3>
          <div class="settings-form">
            <div class="form-item">
              <label>系统语言</label>
              <select v-model="settings.language">
                <option value="zh">中文</option>
                <option value="en">English</option>
              </select>
            </div>
  
            <div class="form-item">
              <label>主题色</label>
              <div class="color-picker">
                <div v-for="color in themeColors" 
                     :key="color.value"
                     class="color-item"
                     :class="{ active: settings.theme === color.value }"
                     :style="{ backgroundColor: color.color }"
                     @click="settings.theme = color.value">
                </div>
              </div>
            </div>
          </div>
        </div>
  
        <!-- 图像处理设置 -->
        <div class="settings-section">
          <h3>图像处理</h3>
          <div class="settings-form">
            <div class="form-item">
              <label>默认图像质量</label>
              <div class="slider-container">
                <input 
                  type="range" 
                  v-model="settings.imageQuality" 
                  min="1" 
                  max="100"
                >
                <span class="slider-value">{{ settings.imageQuality }}%</span>
              </div>
            </div>
  
            <div class="form-item">
              <label>最大图像尺寸</label>
              <select v-model="settings.maxImageSize">
                <option value="1920">1920 x 1080</option>
                <option value="2560">2560 x 1440</option>
                <option value="3840">3840 x 2160</option>
                <option value="0">原始尺寸</option>
              </select>
            </div>
  
            <div class="form-item checkbox">
              <label>
                <input 
                  type="checkbox" 
                  v-model="settings.autoCompress"
                >
                自动压缩大图
              </label>
            </div>
          </div>
        </div>
  
        <!-- AI模型设置 -->
        <div class="settings-section">
          <h3>AI模型设置</h3>
          <div class="settings-form">
            <div class="form-item">
              <label>人脸识别模型</label>
              <select v-model="settings.faceModel">
                <option value="fast">快速模式</option>
                <option value="accurate">精确模式</option>
                <option value="balanced">平衡模式</option>
              </select>
            </div>
  
            <div class="form-item">
              <label>物体识别置信度阈值</label>
              <div class="slider-container">
                <input 
                  type="range" 
                  v-model="settings.objectConfidence" 
                  min="0" 
                  max="100"
                >
                <span class="slider-value">{{ settings.objectConfidence }}%</span>
              </div>
            </div>
  
            <div class="form-item checkbox">
              <label>
                <input 
                  type="checkbox" 
                  v-model="settings.useGPU"
                >
                启用GPU加速
              </label>
            </div>
          </div>
        </div>
  
        <!-- 存储设置 -->
        <div class="settings-section">
          <h3>存储设置</h3>
          <div class="settings-form">
            <div class="form-item">
              <label>存储位置</label>
              <div class="storage-path">
                <input 
                  type="text" 
                  v-model="settings.storagePath"
                  readonly
                >
                <button class="browse-btn">浏览...</button>
              </div>
            </div>
  
            <div class="storage-info">
              <div class="info-item">
                <span>已用空间</span>
                <span>{{ formatSize(storageUsed) }}</span>
              </div>
              <div class="info-item">
                <span>可用空间</span>
                <span>{{ formatSize(storageAvailable) }}</span>
              </div>
            </div>
          </div>
        </div>
      </div>
  
      <div class="settings-footer">
        <button class="save-btn" @click="saveSettings">保存设置</button>
        <button class="reset-btn" @click="resetSettings">恢复默认</button>
      </div>
    </div>
  </template>
  
  <script setup>
  import { ref, reactive } from 'vue'
  
  const themeColors = [
    { value: 'blue', color: '#1890ff' },
    { value: 'green', color: '#52c41a' },
    { value: 'purple', color: '#722ed1' },
    { value: 'red', color: '#f5222d' },
    { value: 'orange', color: '#fa8c16' }
  ]
  
  const settings = reactive({
    language: 'zh',
    theme: 'blue',
    imageQuality: 80,
    maxImageSize: '1920',
    autoCompress: true,
    faceModel: 'balanced',
    objectConfidence: 50,
    useGPU: true,
    storagePath: 'C:/ImageManager/Data'
  })
  
  // 模拟存储信息
  const storageUsed = 1024 * 1024 * 1024 * 2.5 // 2.5 GB
  const storageAvailable = 1024 * 1024 * 1024 * 47.5 // 47.5 GB
  
  const formatSize = (bytes) => {
    const units = ['B', 'KB', 'MB', 'GB', 'TB']
    let size = bytes
    let unitIndex = 0
    
    while (size >= 1024 && unitIndex < units.length - 1) {
      size /= 1024
      unitIndex++
    }
    
    return `${size.toFixed(1)} ${units[unitIndex]}`
  }
  
  const saveSettings = () => {
    // 保存设置到本地存储
    localStorage.setItem('appSettings', JSON.stringify(settings))
    // TODO: 可以添加保存成功的提示
  }
  
  const resetSettings = () => {
    // 重置为默认设置
    Object.assign(settings, {
      language: 'zh',
      theme: 'blue',
      imageQuality: 80,
      maxImageSize: '1920',
      autoCompress: true,
      faceModel: 'balanced',
      objectConfidence: 50,
      useGPU: true,
      storagePath: 'C:/ImageManager/Data'
    })
  }
  </script>
  
  <style scoped>
  .settings {
    height: 100%;
    display: flex;
    flex-direction: column;
    padding: 24px;
    background: #f8f8f8;
  }
  
  .settings-header {
    margin-bottom: 24px;
  }
  
  .description {
    color: #666;
    margin-top: 8px;
  }
  
  .settings-content {
    flex: 1;
    overflow: auto;
    background: white;
    border-radius: 8px;
    padding: 24px;
  }
  
  .settings-section {
    margin-bottom: 32px;
  }
  
  .settings-section h3 {
    margin-bottom: 16px;
    padding-bottom: 8px;
    border-bottom: 1px solid #f0f0f0;
  }
  
  .settings-form {
    display: flex;
    flex-direction: column;
    gap: 16px;
  }
  
  .form-item {
    display: flex;
    flex-direction: column;
    gap: 8px;
  }
  
  .form-item label {
    color: #333;
    font-weight: 500;
  }
  
  select, input[type="text"] {
    padding: 8px;
    border: 1px solid #d9d9d9;
    border-radius: 4px;
    background: white;
  }
  
  .color-picker {
    display: flex;
    gap: 12px;
  }
  
  .color-item {
    width: 24px;
    height: 24px;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.3s;
  }
  
  .color-item.active {
    transform: scale(1.2);
    box-shadow: 0 0 0 2px white, 0 0 0 4px currentColor;
  }
  
  .slider-container {
    display: flex;
    align-items: center;
    gap: 16px;
  }
  
  input[type="range"] {
    flex: 1;
  }
  
  .slider-value {
    min-width: 48px;
    color: #666;
  }
  
  .checkbox {
    flex-direction: row;
    align-items: center;
    gap: 8px;
  }
  
  .checkbox label {
    font-weight: normal;
    color: #666;
    cursor: pointer;
  }
  
  .storage-path {
    display: flex;
    gap: 8px;
  }
  
  .storage-path input {
    flex: 1;
    background: #f5f5f5;
  }
  
  .browse-btn {
    padding: 8px 16px;
    background: #f0f0f0;
    border: none;
    border-radius: 4px;
    cursor: pointer;
  }
  
  .storage-info {
    background: #f5f5f5;
    padding: 12px;
    border-radius: 4px;
  }
  
  .info-item {
    display: flex;
    justify-content: space-between;
    color: #666;
    margin-bottom: 8px;
  }
  
  .info-item:last-child {
    margin-bottom: 0;
  }
  
  .settings-footer {
    margin-top: 24px;
    display: flex;
    gap: 16px;
    justify-content: flex-end;
  }
  
  .save-btn, .reset-btn {
    padding: 8px 24px;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.3s;
  }
  
  .save-btn {
    background: #1890ff;
    color: white;
    border: none;
  }
  
  .save-btn:hover {
    background: #096dd9;
  }
  
  .reset-btn {
    background: white;
    border: 1px solid #d9d9d9;
    color: #666;
  }
  
  .reset-btn:hover {
    border-color: #1890ff;
    color: #1890ff;
  }
  </style>